package com.zhilianbao.leyaogo.ui.adapter.me;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.model.response.me.MyOrderResponse;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.Utils;

import java.util.List;

/**
 * Created by liu on 2016/10/25.
 * 订单详情ListView的adapter
 */
public class OrderHorizontalListAdapter extends BaseAdapter {
    Context mContext;
    List<MyOrderResponse.OrderItemBean> mOrderItem;

    public OrderHorizontalListAdapter(Context context, List<MyOrderResponse.OrderItemBean> orderItem) {
        this.mContext = context;
        this.mOrderItem = orderItem;
    }

    @Override
    public int getCount() {
        return mOrderItem == null ? 0 : mOrderItem.size();
    }

    @Override
    public MyOrderResponse.OrderItemBean getItem(int position) {
        if (mOrderItem != null) {
            mOrderItem.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_horizontal_list_order, null);
            holder.icon = (ImageView) convertView.findViewById(R.id.goods_icon);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ImageUtils.loadGoodsPic(Utils.returnUrlShow(mOrderItem.get(position).getGoodsPic()), holder.icon);
        return convertView;
    }

    class ViewHolder {
        ImageView icon;
    }
}
